\documentclass[12pt]{article}
\usepackage{times}
\usepackage{graphicx}
\usepackage{sidecap}
\usepackage{wrapfig}
\usepackage{fancyhdr}
\usepackage{amsmath}
\pagestyle{fancy}
\renewcommand{\baselinestretch}{1.2}
\newenvironment{mylisting}
{\begin{list}{}{\setlength{\leftmargin}{1em}}\item\scriptsize\bfseries}
{\end{list}}
\newenvironment{mylisting2}
{\begin{list}{}{\setlength{\leftmargin}{1em}}\item\scriptsize\bfseries}
{\end{list}}
\newenvironment{mylisting3}
{\begin{list}{}{\setlength{\leftmargin}{1em}}\item\scriptsize\bfseries}
{\end{list}}
\newenvironment{mylisting4}
{\begin{list}{}{\setlength{\leftmargin}{1em}}\item\scriptsize\bfseries}
{\end{list}}
\newenvironment{mylisting5}
{\begin{list}{}{\setlength{\leftmargin}{1em}}\item\scriptsize\bfseries}
{\end{list}}
\newenvironment{mylisting6}
{\begin{list}{}{\setlength{\leftmargin}{1em}}\item\scriptsize\bfseries}
{\end{list}}
\begin{document}
	\textbf{{\Huge Misc supporting/system code}}
{\center{May 2, 2013, 
	Johan Ceuppens, Theo D'Hondt - Vrije Universiteit Brussel}}
\\

{\center{With thanks to : Ellie D'Hondt, the SOFT lab and the Open Source Community}}

{\large{\textbf{\center Abstract}}}
\\

	This is code which was developed for Java and Ambienttalk/2 systems to provide for computer graphics research. It is a mere illustration.

\section{ Ambienttalk/2 C++ code for an emacs bindings editor (libgtkmm) }
\begin{mylisting}
\begin{verbatim}

/*
Copyright (c) 2013 Software Languages Lab, Vrije Universiteit Brussel

This code is distributed under the MIT License.

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it unde    r the terms of the GNU General Public License as published by the Free Softw    are Foundation; either version 2 of the License, or (at your option) any lat    er version.

This program is distributed in the hope that it will be useful, but WITHOUT     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNES    S FOR A PARTICULAR PURPOSE. See the GNU General Public License for more deta    ils.

You should have received a copy of the GNU General Public License along with     this program; if not, write to the Free Software Foundation, Inc., 59 Templ    e Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _ATEDIT_ATEDITPP_
#define _ATEDIT_ATEDITPP_

#include <gtkmm.h>
#include "filebuffer.h"

class atEditParser
{
public: 
	atEditParser();
	virtual ~atEditParser();

	Glib::ustring parse(atEditFileBuffer const& fbuf);

private:
};

#endif
/*
Copyright (c) 2013 Software Languages Lab, Vrije Universiteit Brussel

This code is distributed under the MIT License.

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it unde    r the terms of the GNU General Public License as published by the Free Softw    are Foundation; either version 2 of the License, or (at your option) any lat    er version.

This program is distributed in the hope that it will be useful, but WITHOUT     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNES    S FOR A PARTICULAR PURPOSE. See the GNU General Public License for more deta    ils.

You should have received a copy of the GNU General Public License along with     this program; if not, write to the Free Software Foundation, Inc., 59 Templ    e Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _ATEDIT_ATEDITCOMMANDS_
#define _ATEDIT_ATEDITCOMMANDS_

#include<gtkmm.h>
#include<exception>
#include<iostream>
class atEditCommand
{
public:
	class popenexception : public std::exception
	{
		virtual const char* what() const throw()
		{
			return "*** popen exception";
		}
	};


	virtual void execute() = 0;
private:
};


class atEditCommandInterprete : public atEditCommand
{
public:
	atEditCommandInterprete(Glib::ustring const& cmdstr);
	virtual ~atEditCommandInterprete();
	void setcommand(Glib::ustring const& cmdstr);
	Glib::ustring get_buffer();
	Glib::ustring get_input();
	Glib::ustring get_output();
	void execute();
private:
	Glib::ustring commandstring;
	Glib::ustring outputstring;
	FILE *outputfilep;
};

#endif
/*
Copyright (c) 2013 Software Languages Lab, Vrije Universiteit Brussel

This code is distributed under the MIT License.

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it unde    r the terms of the GNU General Public License as published by the Free Softw    are Foundation; either version 2 of the License, or (at your option) any lat    er version.

This program is distributed in the hope that it will be useful, but WITHOUT     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNES    S FOR A PARTICULAR PURPOSE. See the GNU General Public License for more deta    ils.

You should have received a copy of the GNU General Public License along with     this program; if not, write to the Free Software Foundation, Inc., 59 Templ    e Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _ATEDIT_ATEDITFILEBUFFER_
#define _ATEDIT_ATEDITFILEBUFFER_

#include <gtkmm.h>
#include<glibmm.h>
class atEditFileBuffer
{
public: 
	atEditFileBuffer();
	void init(Glib::ustring filename);
	virtual ~atEditFileBuffer();

	Glib::ustring get();

	void append(Glib::ustring str); 
	const char*c_str();

	int length();

public:
	char operator[](int ai);//FIXME uchar

private:
	Glib::ustring m_filecontents;
};

#endif
/*
Copyright (c) 2013 Software Languages Lab, Vrije Universiteit Brussel

This code is distributed under the MIT License.

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it unde    r the terms of the GNU General Public License as published by the Free Softw    are Foundation; either version 2 of the License, or (at your option) any lat    er version.

This program is distributed in the hope that it will be useful, but WITHOUT     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNES    S FOR A PARTICULAR PURPOSE. See the GNU General Public License for more deta    ils.

You should have received a copy of the GNU General Public License along with     this program; if not, write to the Free Software Foundation, Inc., 59 Templ    e Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _ATEDIT_ATEDITFILE_
#define _ATEDIT_ATEDITFILE_

#include <gtkmm.h>

class atEditFile
{
public: 
	atEditFile();
	void init(Glib::ustring filename);
	virtual ~atEditFile();

	Glib::ustring get();

private:
	Glib::ustring m_filename;
};

#endif
/*
Copyright (c) 2013 Software Languages Lab, Vrije Universiteit Brussel

This code is distributed under the MIT License.

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it unde    r the terms of the GNU General Public License as published by the Free Softw    are Foundation; either version 2 of the License, or (at your option) any lat    er version.

This program is distributed in the hope that it will be useful, but WITHOUT     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNES    S FOR A PARTICULAR PURPOSE. See the GNU General Public License for more deta    ils.

You should have received a copy of the GNU General Public License along with     this program; if not, write to the Free Software Foundation, Inc., 59 Templ    e Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _ATEDIT_ATEDITWINDOW_
#define _ATEDIT_ATEDITWINDOW_

#include <gtkmm.h>
#include "file.h"
#include "filebuffer.h"
#include "atpp.h"

class atEditWindow : public Gtk::Window
{
public: 
	atEditWindow();
	virtual ~atEditWindow();

private:
	atEditFile m_file;
	atEditFileBuffer m_filebuffer;
	atEditParser m_parser;

protected:

	void clickedOpenButton();

	Gtk::Button m_openbutton;

 //Child widgets:
  Gtk::Box m_VBox;

  Gtk::ScrolledWindow m_ScrolledWindow;
  Gtk::TextView m_TextView;

  Glib::RefPtr<Gtk::TextBuffer> m_refTextBuffer1, m_refTextBuffer2;

  Gtk::ButtonBox m_ButtonBox;
  Gtk::Button m_Button_Quit, m_Button_Buffer1, m_Button_Buffer2;

void fill_buffers(Glib::ustring filename);
void on_button_buffer1();
void on_button_buffer2();
void on_button_quit();
};

#endif
/*
Copyright (c) 2013 Software Languages Lab, Vrije Universiteit Brussel

This code is distributed under the MIT License.

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it unde    r the terms of the GNU General Public License as published by the Free Softw    are Foundation; either version 2 of the License, or (at your option) any lat    er version.

This program is distributed in the hope that it will be useful, but WITHOUT     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNES    S FOR A PARTICULAR PURPOSE. See the GNU General Public License for more deta    ils.

You should have received a copy of the GNU General Public License along with     this program; if not, write to the Free Software Foundation, Inc., 59 Templ    e Place, Suite 330, Boston, MA 02111-1307 USA
*/

#include<gtkmm.h>
#include "atpp.h"
#include<iostream>
#include<pcrecpp.h>

atEditParser::atEditParser()
{
}

atEditParser::~atEditParser()
{}
	
Glib::ustring atEditParser::parse(atEditFileBuffer const& fbuf)
{

	Glib::ustring endcontents;
	Glib::ustring tmpcontents;

	int i = 0;
	while (i < const_cast<atEditFileBuffer&>(fbuf).length()) {

		switch (const_cast<atEditFileBuffer&>(fbuf)[i]){
		case '{':{
			pcrecpp::RE re("def ");
			if (re.FullMatch(tmpcontents.c_str())) {
				endcontents += tmpcontents;
				endcontents += "{\n";
				tmpcontents.clear();
			}
			i++;
			continue;
		}
		case ';':{	
			endcontents += tmpcontents;
			endcontents += ";\n";
			tmpcontents.clear();
			i++;
			continue;
		}
		default:{
			break;
		}
		}
		tmpcontents.push_back(const_cast<atEditFileBuffer&>(fbuf)[i]);
		i++;	
	}

	return endcontents;
}

/*
Copyright (c) 2013 Software Languages Lab, Vrije Universiteit Brussel

This code is distributed under the MIT License.

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it unde    r the terms of the GNU General Public License as published by the Free Softw    are Foundation; either version 2 of the License, or (at your option) any lat    er version.

This program is distributed in the hope that it will be useful, but WITHOUT     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNES    S FOR A PARTICULAR PURPOSE. See the GNU General Public License for more deta    ils.

You should have received a copy of the GNU General Public License along with     this program; if not, write to the Free Software Foundation, Inc., 59 Templ    e Place, Suite 330, Boston, MA 02111-1307 USA
*/

#include <gtkmm.h>
#include "commands.h"
#include <iostream>
#include<exception>

atEditCommandInterprete::atEditCommandInterprete(Glib::ustring const& cmdstr) 
	: commandstring(cmdstr)
{}

atEditCommandInterprete::~atEditCommandInterprete()
{}

void atEditCommandInterprete::setcommand(Glib::ustring const& cmdstr)
{
	commandstring = cmdstr;
}
	
Glib::ustring atEditCommandInterprete::get_input()
{
	return commandstring;
}

Glib::ustring atEditCommandInterprete::get_output()
{
	return outputstring;
}

void atEditCommandInterprete::execute()
{
	try {
		outputfilep = popen(commandstring.c_str(), "r");

		outputstring = "";

		if (outputfilep == NULL) throw(popenexception());
	
		char c;
		while ((c = getc(outputfilep)) != EOF)
			outputstring.push_back(c);

		if (c != EOF)
			throw(popenexception());

	} catch (std::exception& e) {
		std::cerr << e.what() << std::endl;
	}
}

/*
Copyright (c) 2013 Software Languages Lab, Vrije Universiteit Brussel

This code is distributed under the MIT License.

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it unde    r the terms of the GNU General Public License as published by the Free Softw    are Foundation; either version 2 of the License, or (at your option) any lat    er version.

This program is distributed in the hope that it will be useful, but WITHOUT     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNES    S FOR A PARTICULAR PURPOSE. See the GNU General Public License for more deta    ils.

You should have received a copy of the GNU General Public License along with     this program; if not, write to the Free Software Foundation, Inc., 59 Templ    e Place, Suite 330, Boston, MA 02111-1307 USA
*/

#include <gtkmm.h>
#include "filebuffer.h"
#include <iostream>

atEditFileBuffer::atEditFileBuffer()
{
}

void atEditFileBuffer::init(Glib::ustring filecontents)
{
	m_filecontents = filecontents;
}

atEditFileBuffer::~atEditFileBuffer()
{}
	
Glib::ustring atEditFileBuffer::get()
{
	return m_filecontents;
}
	
void atEditFileBuffer::append(Glib::ustring str)
{

	m_filecontents += str;
	
}

const char*atEditFileBuffer::c_str()
{
	return m_filecontents.c_str();
}

int atEditFileBuffer::length()
{
	return m_filecontents.length();
}

char atEditFileBuffer::operator[](int ai)//FIXME return uchar
{
	return m_filecontents[ai];
}

/*
Copyright (c) 2013 Software Languages Lab, Vrije Universiteit Brussel

This code is distributed under the MIT License.

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it unde    r the terms of the GNU General Public License as published by the Free Softw    are Foundation; either version 2 of the License, or (at your option) any lat    er version.

This program is distributed in the hope that it will be useful, but WITHOUT     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNES    S FOR A PARTICULAR PURPOSE. See the GNU General Public License for more deta    ils.

You should have received a copy of the GNU General Public License along with     this program; if not, write to the Free Software Foundation, Inc., 59 Templ    e Place, Suite 330, Boston, MA 02111-1307 USA
*/

#include <gtkmm.h>
#include "file.h"
#include <iostream>

atEditFile::atEditFile()
{
}

void atEditFile::init(Glib::ustring filename)
{
	m_filename = filename;
}

atEditFile::~atEditFile()
{}
	
Glib::ustring atEditFile::get()
{
	return m_filename;
}

/*
Copyright (c) 2013 Software Languages Lab, Vrije Universiteit Brussel

This code is distributed under the MIT License.

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it unde    r the terms of the GNU General Public License as published by the Free Softw    are Foundation; either version 2 of the License, or (at your option) any lat    er version.

This program is distributed in the hope that it will be useful, but WITHOUT     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNES    S FOR A PARTICULAR PURPOSE. See the GNU General Public License for more deta    ils.

You should have received a copy of the GNU General Public License along with     this program; if not, write to the Free Software Foundation, Inc., 59 Templ    e Place, Suite 330, Boston, MA 02111-1307 USA
*/

#include "window.h"
#include <gtkmm.h>
#include<iostream>

void printusage();

int main(int argc, char *argv[])
{

//  if (argc < 2) {
//	printusage();
//	exit(0);
//  }

  Glib::RefPtr<Gtk::Application> app =
    Gtk::Application::create(argc, argv,
      "org.gtkmm.examples.base");

 // Gtk::ApplicationWindow window;
//  atEditWindow ateditwindow(argv[1]);
  atEditWindow ateditwindow;//FIXMENOTE if this file is not present , the app does not load, it gets loaded default in the buffer
  return app->run(ateditwindow);
}

void printusage()
{
	std::cout << "atEditLin <filename>" << std::endl;
}
/*
Copyright (c) 2013 Software Languages Lab, Vrije Universiteit Brussel

This code is distributed under the MIT License.

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it unde    r the terms of the GNU General Public License as published by the Free Softw    are Foundation; either version 2 of the License, or (at your option) any lat    er version.

This program is distributed in the hope that it will be useful, but WITHOUT     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNES    S FOR A PARTICULAR PURPOSE. See the GNU General Public License for more deta    ils.

You should have received a copy of the GNU General Public License along with     this program; if not, write to the Free Software Foundation, Inc., 59 Templ    e Place, Suite 330, Boston, MA 02111-1307 USA
*/

#include<gtkmm.h>
#include<gdkmm.h>
#include<gdkmm/window.h>
#include "window.h"
#include<iostream>
#include<fstream>
#include<vector>

atEditWindow::atEditWindow() : m_openbutton("Open"),
 m_VBox(Gtk::ORIENTATION_VERTICAL),
  m_Button_Quit(Gtk::Stock::QUIT),
  m_Button_Buffer1("Open"),
  m_Button_Buffer2("Save")
{

	//m_file.init(filename);
	//m_filebuffer.init(filename);
	set_border_width(5);
/*
	m_openbutton.signal_clicked().connect(sigc::mem_fun(*this,
						&atEditWindow::clickedOpenButton));

	add(m_openbutton);
	//m_openbutton.show();
*/

	set_title("atEdit");
	set_default_size(800,600);

	add(m_VBox);

	//Add the TreeView, inside a ScrolledWindow, with the button underneath:
  m_ScrolledWindow.add(m_TextView);

  //Only show the scrollbars when they are necessary:
  m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);

  m_VBox.pack_start(m_ScrolledWindow);

  //Add buttons:
  m_VBox.pack_start(m_ButtonBox, Gtk::PACK_SHRINK);

  m_ButtonBox.pack_start(m_Button_Buffer1, Gtk::PACK_SHRINK);
  m_ButtonBox.pack_start(m_Button_Buffer2, Gtk::PACK_SHRINK);
  m_ButtonBox.pack_start(m_Button_Quit, Gtk::PACK_SHRINK);
  m_ButtonBox.set_border_width(5);
  m_ButtonBox.set_spacing(5);
  m_ButtonBox.set_layout(Gtk::BUTTONBOX_END);

  //Connect signals:
  m_Button_Quit.signal_clicked().connect(sigc::mem_fun(*this,
              &atEditWindow::on_button_quit) );
  m_Button_Buffer1.signal_clicked().connect(sigc::mem_fun(*this,
              &atEditWindow::on_button_buffer1) );
  m_Button_Buffer2.signal_clicked().connect(sigc::mem_fun(*this,
              &atEditWindow::on_button_buffer2) );

  //fill_buffers(filename);
  

  show_all_children();
}

atEditWindow::~atEditWindow()
{}

void atEditWindow::clickedOpenButton()
{
	std::cout << "clicked Open" << std::endl;
}

void atEditWindow::on_button_buffer1()
{

	Gtk::FileChooserDialog dialog("Please choose a folder", Gtk::FILE_CHOOSER_ACTION_OPEN);
	dialog.set_transient_for(*this);	

	dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
	dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);

	Glib::RefPtr<Gtk::FileFilter> filter_any = Gtk::FileFilter::create();
	filter_any->set_name("Any files");
	filter_any->add_pattern("*");
	dialog.add_filter(filter_any);

	int result = dialog.run();

	switch(result){
	case(Gtk::RESPONSE_OK):{
		fill_buffers(dialog.get_filename());
		break;
	}
	case(Gtk::RESPONSE_CANCEL):
	default:{
		break;
	}
	}
/*TODO
	std::vector< Glib::RefPtr<Gtk::TextTag> >tags;
	Gtk::TextIter iter;
	Glib::RefPtr<Gtk::TextTag> tag;
	tag = m_refTextBuffer1->create_tag("blue_fg");
	//tag->set_property("color", Pango::Color);
	tag->set_property("color", "blue");

	tags.push_back(tag);
	iter = m_refTextBuffer1->end();
	m_refTextBuffer1->insert_with_tags(iter, "in blue color", tags);	
*/
/*
	Glib::<RefPtr<Pango::Layout > m_refLayout;

	m_refLayout = print_context->create_pango_layout();
*/
/*	Gdk::Color green;
	Glib::RefPtr<Gdk::GC> gc;
	gc = Gdk::GC::create(this);
	gc->set_foreground(green);
*/	
	m_TextView.set_buffer(m_refTextBuffer1);
}

void atEditWindow::on_button_buffer2()
{
	//m_TextView.set_buffer(m_refTextBuffer2);
	Glib::RefPtr<Gtk::TextBuffer> buf = m_TextView.get_buffer();

	std::ofstream ofs;
	ofs.open(m_file.get().c_str());
	ofs << buf->get_text().c_str();
	ofs.close();

	//DEBUG std::cout << buf->get_text().c_str() << std::endl; 

	return;

}

void atEditWindow::on_button_quit()
{
	hide();
}

void atEditWindow::fill_buffers(Glib::ustring filename)
{
	m_refTextBuffer1 = Gtk::TextBuffer::create();

	m_file.init(filename);
	m_filebuffer.init(filename);

	std::ifstream ifs;
	ifs.open(m_file.get().c_str());//ios::in

	while (!ifs.eof()) {
	
		Glib::ustring buffercontents;
		ifs >> buffercontents;

		if (buffercontents == "\n") {
			m_filebuffer.append("\n");
			continue;
		} else {
			m_filebuffer.append(" ");
		}

		m_filebuffer.append(buffercontents.c_str());//FIXME operator +=, +//FIXME override Glib::ustring for this app and others
	}

	ifs.close();

  Glib::ustring parsedcontents = m_parser.parse(m_filebuffer);

  m_refTextBuffer1->set_text(parsedcontents.c_str());

	std::vector< Glib::RefPtr<Gtk::TextTag> >tags;
	Gtk::TextIter iter;
	Glib::RefPtr<Gtk::TextTag> tag;
	tag = m_refTextBuffer1->create_tag("bold");
	tag->set_property("weight", Pango::WEIGHT_BOLD);

	tags.push_back(tag);
	iter = m_refTextBuffer1->end();
	m_refTextBuffer1->insert_with_tags(iter, "in bold", tags);	
	
	//insert_with_tags_by_name(iter, "foo123", 

  m_refTextBuffer2 = Gtk::TextBuffer::create();
  m_refTextBuffer2->set_text("This is at code.2");
//  m_ButtonBox.pack_start(m_Button_Buffer2, Gtk::PACK_SHRINK);

}


# Set the default color scheme:
gtk_color_scheme = "fg_color:#000\nbg_color:#ede9e3\nbase_color:#fff\ntext_color:#000\nselected_bg_color:#5598d7\nselected_fg_color:#fff"
style "default"
{
  fg[NORMAL]        = @fg_color
  fg[PRELIGHT]      = @fg_color
  fg[SELECTED]      = @selected_fg_color
  fg[ACTIVE]        = @fg_color
  # There are color expressions to change the colors
  fg[INSENSITIVE]   = darker (@bg_color)
  [...]
}
style "progress"
{
  # You can override symbolic colors per style (XXX did I get this right?)
  color["fg_color"] = "#00ff00"
  # Not that this will *NOT* change the foreground colors as they
  # were set in the default style. For that to work, everything using
  # fg_color needs to be copied.
  # This is a design limitation. (Hm, should report a bug really ...)
  fg[NORMAL]        = @fg_color
  fg[PRELIGHT]      = @fg_color
  fg[ACTIVE]        = @fg_color
}
class "GtkWidget"    style "default"
class "GtkProgress"  style "default"

\end{verbatim}
\end{mylisting}

\section{\large Conclusion}


\bibliographystyle{plain}
\bibliography{plasmascreen} % refs.bib

\end{document}

%%



